package cosw.com.shanghaica;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.cosw.sdkShanghaiCA.EnumError;
import com.cosw.sdkShanghaiCA.SHCAProvider;

public class CreateContainerActivity extends ActionBarActivity {

  @BindView(R.id.tv_container_name)
  TextView tvContainerName;
  @BindView(R.id.tv_container_pwd)
  TextView tvContainerPwd;
  @BindView(R.id.et_container_name)
  EditText etContainerName;
  @BindView(R.id.et_container_pwd)
  EditText etUserPin;
  @BindView(R.id.btn_confirm)
  Button btnConfirm;

  private SHCAProvider provider;

  private Context mContext;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_container);
    ButterKnife.bind(this);

    mContext = this;

    provider = SHCAProvider.getInstance(this.getApplication());
  }

  @OnClick(R.id.btn_confirm)
  public void onViewClicked() {
    String containerName = etContainerName.getText().toString();
    String userPin = etUserPin.getText().toString();
    int result = provider.createContainer(containerName, userPin);
    if (EnumError.SUCCESS.getResCode() == result) {
      Toast.makeText(mContext, "容器创建成功！", Toast.LENGTH_SHORT).show();
      finish();
    } else {
      Toast.makeText(mContext, EnumError.getEnumName(result), Toast.LENGTH_SHORT).show();
    }
  }
}
